﻿using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Accona.Monitoring.AppStatistics;

namespace Accona.Monitoring.Publishers.Multicast
{
    public class MulticastExposure : IPublisher
    {
        private readonly MulticastSender sender;

        public MulticastExposure(string multicastGroup, int port, int ttl)
        {
            sender = new MulticastSender(multicastGroup,port,ttl);
            
        }

        public void Publish(AppStatisticsEvent appStatisticsEvent)
        {
            var buffer = new byte[1400];
            var stream = new MemoryStream(buffer);
            var formatter = new BinaryFormatter();
            formatter.Serialize(stream, appStatisticsEvent);                        
            sender.Send(buffer);
        }
    }
}
